package com.A21.GuoSai.demo.service_entity.test;

import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.model.bpmn.instance.ConditionExpression;
import io.camunda.zeebe.model.bpmn.instance.ExclusiveGateway;
import io.camunda.zeebe.model.bpmn.instance.SequenceFlow;
import org.camunda.feel.FeelEngine;
import org.junit.jupiter.api.Test;
import scala.util.Either;

import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class TryToJudge {

    @Test
//    获取条件结点的信息
    public void getExclusiveGateWay(){
        InputStream input=this.getClass().getClassLoader().getResourceAsStream("processes/purchase.bpmn");
        BpmnModelInstance modelInstance= Bpmn.readModelFromStream(input);

        Collection<ExclusiveGateway> exclusiveGateways= modelInstance.getModelElementsByType(ExclusiveGateway.class);

//        exclusiveGateway就是If结点，incoming和outgoing分别指节点的输入和输出
//        结点可以由多个输入和输出，所以这里的incoming和outcoming都是用Collection保存的
        for(ExclusiveGateway task : exclusiveGateways){
            System.out.print("incoming:");
            for(SequenceFlow incoming:task.getIncoming())
                System.out.print(incoming.getId()+",");
            System.out.println();

            System.out.print("outgoing:");
            for(SequenceFlow outgoing:task.getOutgoing()) {
                System.out.print(outgoing.getId() + ",");
                ConditionExpression expression=outgoing.getConditionExpression();
                if(expression!=null)
                    System.out.println(outgoing.getConditionExpression().getRawTextContent().substring(1));
            }
        }
    }

    @Test
    public void JudgeTest01(){
        //创建一个新的Feel语言引擎
        FeelEngine feelEngine=new FeelEngine.Builder().build();
        Map<String,Object> map=new HashMap<>();

        Either<FeelEngine.Failure, Object> failureObjectEither = feelEngine.evalExpression("commodity.data > 30", map);
        System.out.println(failureObjectEither.toString());
    }
}
